package cn.iocoder.yudao.module.wine.controller.app.supplyoptional;

import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;

import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Operation;

import javax.validation.*;
import java.util.*;

import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.*;

import cn.iocoder.yudao.module.wine.controller.app.supplyoptional.vo.*;
import cn.iocoder.yudao.module.wine.dal.dataobject.supplyoptional.SupplyOptionalDO;
import cn.iocoder.yudao.module.wine.service.supplyoptional.SupplyOptionalService;

@Tag(name = "用户 APP - 供求自选条件")
@RestController
@RequestMapping("/wine/supply-optional")
@Validated
public class AppSupplyOptionalController {

    @Resource
    private SupplyOptionalService supplyOptionalService;

    @PostMapping("/create")
    @Operation(summary = "创建供求自选条件")
    public CommonResult<Long> createSupplyOptional(@Valid @RequestBody AppSupplyOptionalSaveReqVO createReqVO) {
        return success(supplyOptionalService.createSupplyOptional(createReqVO));
    }

    @PutMapping("/update")
    @Operation(summary = "置顶")
    public CommonResult<Boolean> updateSupplyOptional(@Valid @RequestBody AppSupplyOptionalSaveReqVO updateReqVO) {
        supplyOptionalService.updateSupplyOptional(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除供求自选条件")
    @Parameter(name = "id", description = "编号", required = true)
    public CommonResult<Boolean> deleteSupplyOptional(@RequestParam("id") Long id) {
        supplyOptionalService.deleteSupplyOptional(id);
        return success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "获得供求自选条件")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    public CommonResult<AppSupplyOptionalRespVO> getSupplyOptional(@RequestParam("id") Long id) {
        SupplyOptionalDO supplyOptional = supplyOptionalService.getSupplyOptional(id);
        return success(BeanUtils.toBean(supplyOptional, AppSupplyOptionalRespVO.class));
    }

    @GetMapping("/list")
    @Operation(summary = "获得供求自选条件列表")
    public CommonResult<List<AppSupplyOptionalRespVO>> getSupplyOptionalPage(@Valid AppSupplyOptionalPageReqVO pageReqVO) {
        List<AppSupplyOptionalRespVO> list = supplyOptionalService.getSupplyOptionalList(pageReqVO);
        return success(BeanUtils.toBean(list, AppSupplyOptionalRespVO.class));
    }
}
